package com.songshuang.myutilsboot.stlf.core;

final class ExponentialSmoothing {
    private ExponentialSmoothing() {}

    // 双指数平滑与C++实现一致（s1、s2、a、b）
    static double[] forecast(double[] x, int n, int fn, double wt) {
        double[] s1 = new double[n + 1];
        double[] s2 = new double[n + 1];
        double[] a = new double[n + 1];
        double[] b = new double[n + 1];
        for (int i = 1; i <= n; i++) {
            if (i == 1) { s1[1] = x[1]; continue; }
            s1[i] = x[i] * wt + (1 - wt) * s1[i - 1];
        }
        for (int i = 1; i <= n; i++) {
            if (i == 1) { s2[1] = s1[1]; continue; }
            s2[i] = s1[i] * wt + (1 - wt) * s2[i - 1];
        }
        for (int i = 1; i <= n; i++) a[i] = 2 * s1[i] - s2[i];
        for (int i = 1; i <= n; i++) b[i] = (s1[i] - s2[i]) * wt / (1 - wt);
        double[] f = new double[fn + 1];
        for (int i = 1; i <= fn; i++) f[i] = a[n] + b[n] * i;
        return f;
    }
}


